package com.csyaonie.android;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.csyaonie.android.broadcast.BroadcastActivity1;
import com.csyaonie.android.contentresolver.ReadContactsActivity;
import com.csyaonie.android.fragment.FragmentActivity;
import com.csyaonie.android.jump.AActivity;
import com.csyaonie.android.storage.StorageActivity;
import com.csyaonie.android.utils.ToastUtil;

public class MainActivity extends AppCompatActivity {

    private Button ui_bt;
    private Button life_cycle_bt;
    private Button jump_bt;
    private Button fragment_bt;
    private Button event_bt;
    private Button handler_bt;
    private Button storage_bt;
    private Button broadcast_bt;
    private Button animate_bt;
    private Button permission_bt;
    private Button content_bt;
    private Button notification_bt;
    private Button camera_bt;
    private Button http_bt;
    private Button service_bt;
    private Button servicebt1;
    private Button servicebt2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ui_bt=findViewById(R.id.ui_bt);
        life_cycle_bt=findViewById(R.id.life_cycle_bt);
        jump_bt=findViewById(R.id.jump_bt);
        fragment_bt=findViewById(R.id.fragment_bt);
        event_bt=findViewById(R.id.event_bt);
        handler_bt=findViewById(R.id.handler_bt);
        storage_bt=findViewById(R.id.storage_bt);
        broadcast_bt=findViewById(R.id.broadcast_bt);
        animate_bt=findViewById(R.id.animate_bt);
        permission_bt=findViewById(R.id.permission_bt);
        content_bt=findViewById(R.id.content_bt);
        notification_bt=findViewById(R.id.notification_bt);
        camera_bt=findViewById(R.id.camera_bt);
        http_bt=findViewById(R.id.http_bt);
        service_bt=findViewById(R.id.service_bt);
        setListener();
    }

    public void setListener(){
        MainActivity.Onclick onclick=new MainActivity.Onclick();
        ui_bt.setOnClickListener(onclick);
        life_cycle_bt.setOnClickListener(onclick);
        jump_bt.setOnClickListener(onclick);
        fragment_bt.setOnClickListener(onclick);
        event_bt.setOnClickListener(onclick);
        handler_bt.setOnClickListener(onclick);
        storage_bt.setOnClickListener(onclick);
        broadcast_bt.setOnClickListener(onclick);
        animate_bt.setOnClickListener(onclick);
        permission_bt.setOnClickListener(onclick);
        content_bt.setOnClickListener(onclick);
        notification_bt.setOnClickListener(onclick);
        camera_bt.setOnClickListener(onclick);
        http_bt.setOnClickListener(onclick);
        service_bt.setOnClickListener(onclick);
    }

    public class Onclick implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            Intent intent = null;
            switch (v.getId()) {
                case R.id.ui_bt:
                    intent = new Intent(MainActivity.this, UiActivity.class);
                    break;
                case R.id.life_cycle_bt:
                    intent = new Intent(MainActivity.this, LifeCycleActivity.class);
                    break;
                case R.id.jump_bt:
                    intent = new Intent(MainActivity.this, AActivity.class);
                    break;
                case R.id.fragment_bt:
                    intent = new Intent(MainActivity.this, FragmentActivity.class);
                    break;
                case R.id.event_bt:
                    intent = new Intent(MainActivity.this, EventActivity.class);
                    break;
                case R.id.handler_bt:
                    intent = new Intent(MainActivity.this, HandlerActivity.class);
                    break;
                case R.id.storage_bt:
                    intent = new Intent(MainActivity.this, StorageActivity.class);
                    break;
                case R.id.broadcast_bt:
                    intent = new Intent(MainActivity.this, BroadcastActivity1.class);
                    break;
                case R.id.animate_bt:
                    intent = new Intent(MainActivity.this, AnimateActivity.class);
                    break;
                case R.id.permission_bt:
                    intent = new Intent(MainActivity.this, PermissionActivity.class);
                    break;
                case R.id.content_bt:
                    intent = new Intent(MainActivity.this, ReadContactsActivity.class);
                    break;
                case R.id.notification_bt:
                    intent = new Intent(MainActivity.this, NotificationActivity.class);
                    break;
                case R.id.camera_bt:
                    intent = new Intent(MainActivity.this, CameraActivity.class);
                    break;
                case R.id.http_bt:
                    intent = new Intent(MainActivity.this, HttpActivity.class);
                    break;
                case R.id.service_bt:
                    intent = new Intent(MainActivity.this, ServiceActivity.class);
                    break;
            }
            startActivity(intent);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()){
            case R.id.add_item:
                ToastUtil.show(MainActivity.this,"add");
                break;
            case R.id.remove_item:
                ToastUtil.show(MainActivity.this,"remove");
                break;
        }
        return true;
    }
}